package com.hup.utils.commons.thread;

import com.hup.utils.commons.exception.AppCommonException;
import lombok.extern.log4j.Log4j2;

/**
 * @author hugan
 * @date 2020/3/2
 */
@Log4j2
public class ThreadUtil {

    public static Thread start(Runnable runnable) {
        Thread thread = new Thread(runnable);
        thread.start();
        return thread;
    }

    public static void sleep(long time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            log.error("InterruptedException", e);
            Thread.currentThread().interrupt();
            throw new AppCommonException(e.toString());
        }
    }

    public static void handleInterruptedException(InterruptedException e) {
        log.error("InterruptedException", e);
        Thread.currentThread().interrupt();
        throw new AppCommonException(e.toString());
    }

}
